package io;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

/** 单字节文件复制 */
public class CopyDemo {
    public static void main(String[] args) throws IOException {
        FileInputStream fis1=new FileInputStream("K.jpg");
        FileOutputStream fos1=new FileOutputStream("K_cp.jpg");
        long start1=System.currentTimeMillis();
        int d1;
        while ((d1=fis1.read())!=-1){
            fos1.write(d1);
        }
        long end1=System.currentTimeMillis();
        System.out.println("复制完毕！耗时:"+(end1-start1)+"ms");
        fis1.close();
        fos1.close();



        FileInputStream fis2=new FileInputStream("K.jpg");
        FileOutputStream fos2=new FileOutputStream("K1_cp.jpg");
        long start2=System.currentTimeMillis();
        int d2;
        while ((d2=fis2.read())!=-1){
            fos2.write(d2);
        }
        long end2=System.currentTimeMillis();
        System.out.println("复制完毕!耗时:"+(end2-start2)+"ms");
        fis2.close();
        fos2.close();
    }
}
